package utils;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;

import java.sql.Connection;

public class JDBCUtils {
	private static String driver;
	private static String url;
	private static String user;
	private static String password;
	static{
		Properties p=new Properties();
		try {
			p.load(new FileInputStream(JDBCUtils.class.getResource("jdbc.properties").getFile()));
			driver=p.getProperty("driver");
			url=p.getProperty("url");
			user=p.getProperty("user");
			password=p.getProperty("password");
			
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	public static Connection getConnection() {
		
		try {
			Class.forName(driver);
			Connection connection=DriverManager.getConnection(url,user,password);
			return connection;
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return null;
	}


}
